package dm71.espil.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import dm71.espil.R;
import dm71.espil.R.id;
import dm71.espil.R.layout;
import dm71.espil.REST.DataService;
import dm71.espil.models.User;

public class RedigerProfilActivity extends Activity 
{
	EditText editBrugernavn; 
	EditText editPassword; 
	EditText editName; 
	EditText editEfternavn; 
	EditText editKlasse;
	
	RedigerProfilActivity context = this;
	
	User currentUser;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.redigerprofil);
        
        Button butRediger = (Button) findViewById(R.id.butRediger);
    	editBrugernavn = (EditText) findViewById(R.id.editRedBrugernavn);
    	editPassword = (EditText) findViewById(R.id.editRedPassword);
    	editName = (EditText) findViewById(R.id.editTextRedNavn);
    	editEfternavn = (EditText) findViewById(R.id.editTextRedLastname);
    	editKlasse = (EditText) findViewById(R.id.editTextRedClass);
    	
    	requestProfil();
    	editBrugernavn.setText(currentUser.getUsername());
    	editPassword.setText(currentUser.getPassword());
    	editName.setText(currentUser.getName());
    	editEfternavn.setText(currentUser.getLastName());
    	editKlasse.setText(currentUser.getKlasse());
    	
        butRediger.setOnClickListener(new OnClickListener()
        {
        	//@Override
        	public void onClick(View v)
        	{
        		DataService ds = new DataService();
        		ds.EditUser(currentUser.UserID, editBrugernavn.getText().toString(), editPassword.getText().toString(), editName.getText().toString(), editEfternavn.getText().toString(), editKlasse.getText().toString());
        		
        		Intent intent = new Intent(context, MainMenuActivity.class);
        		startActivity(intent);
        	}
        });
	}
	
	public void requestProfil()
	{
		DataService ds = new DataService();
		currentUser = ds.Request(0);
		
	}
}
